import { simpleCall, simpleDelCall, simplePostCall, simplePutCall } from '../utils/Action';
import type { SearchPaginationInput, VulnerabilityCreateInput, VulnerabilitySimple, VulnerabilityUpdateInput } from '../utils/api-types';

const VULNERABILITY_URI = '/api/vulnerabilities';

export const searchVulnerabilities = (searchPaginationInput: SearchPaginationInput) => {
  const data = searchPaginationInput;
  const uri = `${VULNERABILITY_URI}/search`;
  return simplePostCall(uri, data);
};

export const fetchVulnerability = (vulnerabilityId: string) => {
  const uri = `${VULNERABILITY_URI}/${vulnerabilityId}`;
  return simpleCall(uri);
};

export const fetchVulnerabilityByExternalId = (vulnerabilityId: string) => {
  const uri = `${VULNERABILITY_URI}/external-id/${vulnerabilityId}`;
  return simpleCall(uri);
};

export const addVulnerability = (data: VulnerabilityCreateInput) => {
  return simplePostCall(`${VULNERABILITY_URI}`, data);
};

export const updateVulnerability = (vulnerabilityId: VulnerabilitySimple['vulnerability_id'], data: VulnerabilityUpdateInput) => {
  const uri = `${VULNERABILITY_URI}/${vulnerabilityId}`;
  return simplePutCall(uri, data);
};

export const deleteVulnerability = (vulnerabilityId: VulnerabilitySimple['vulnerability_id']) => {
  const uri = `${VULNERABILITY_URI}/${vulnerabilityId}`;
  return simpleDelCall(uri);
};
